package com.quanxiaoha.xiaohashu.auth.rpc;


import com.quanxiaoha.framework.common.response.Response;
import com.quanxiaoha.xiaohashu.user.api.UserFeignApi;
import com.quanxiaoha.xiaohashu.user.dto.req.FindUserByPhoneReqDTO;
import com.quanxiaoha.xiaohashu.user.dto.req.RegisterUserReqDTO;
import com.quanxiaoha.xiaohashu.user.dto.req.UpdateUserPasswordReqDTO;
import com.quanxiaoha.xiaohashu.user.dto.resp.FindUserByPhoneRspDTO;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;

/**
 * @Author: jingyan_liu
 * @CreateTime: 2025-07-22
 * @Description:
 * @Version: 1.0
 */

@Component
public class UserRpcService {
	
	@Resource
	private UserFeignApi userFeignApi;
	
	public Long registerUser(String phone) {
		RegisterUserReqDTO registerUserReqDTO = new RegisterUserReqDTO();
		registerUserReqDTO.setPhone(phone);
		
		Response<Long> response = userFeignApi.registerUser(registerUserReqDTO);
		
		return response.isSuccess() ? response.getData() : null;
	}
	
	public FindUserByPhoneRspDTO findUserByPhone(String phone) {
		FindUserByPhoneReqDTO findUserByPhoneReqDTO = new FindUserByPhoneReqDTO();
		findUserByPhoneReqDTO.setPhone(phone);
		
		Response<FindUserByPhoneRspDTO> response = userFeignApi.findByPhone(findUserByPhoneReqDTO);
		
		return response.isSuccess() ? response.getData() : null;
	}
	
	public void updatePassword(String encodePassword) {
		UpdateUserPasswordReqDTO updateUserPasswordReqDTO = new UpdateUserPasswordReqDTO();
		updateUserPasswordReqDTO.setEncodePassword(encodePassword);
		
		userFeignApi.updatePassword(updateUserPasswordReqDTO);
	}
	
}
